package com.sugon.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.SysUserMsgDao;
import com.sugon.entity.SysUserMsgEntity;
import com.sugon.service.SysUserMsgService;
import com.sugon.utils.ApiRRException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 系统用户Service实现类
 *
 * @author sugon
 * @date 2019-07-15 17:04:30
 */
@Slf4j
@Service("sysUserMsgService")
public class SysUserMsgServiceImpl implements SysUserMsgService {
    @Autowired
    private SysUserMsgDao sysUserMsgDao;

    /**
     * queryObject
     *
     * @param userId 主键
     * @return
     */
    @Override
    public SysUserMsgEntity queryObject(String userId) {
        return sysUserMsgDao.queryObject(userId);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<SysUserMsgEntity> queryList(Map<String, Object> map) {
        return sysUserMsgDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return sysUserMsgDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param sysUser 实体
     * @return
     */
    @Override
    public int save(SysUserMsgEntity sysUser) {
        sysUser.setUserId(RandomUtil.randomString(32));
        return sysUserMsgDao.save(sysUser);
    }

    /**
     * update
     *
     * @param sysUser 实体
     * @return
     */
    @Override
    public int update(SysUserMsgEntity sysUser) {
        return sysUserMsgDao.update(sysUser);
    }

    /**
     * delete
     *
     * @param userId
     * @return
     */
    @Override
    public int delete(String userId) {
        return sysUserMsgDao.delete(userId);
    }

    /**
     * deleteBatch
     *
     * @param userIds
     * @return
     */
    @Override
    public int deleteBatch(String[] userIds) {
        return sysUserMsgDao.deleteBatch(userIds);
    }

    /**
     * queryUserMsg
     *
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Object>> queryUserMsg(String id) {
        try {
            List<Map<String, Object>> lm = sysUserMsgDao.selectUserMsg(id);
            List listMsg = new ArrayList();
            for (Map<String, Object> mapMsg : lm) {
                switch (mapMsg.get("MSGTYPE").toString()) {
                    case "1":
                        mapMsg.put("MSGTYPE", "催办事项");
                        break;
                    case "2":
                        mapMsg.put("MSGTYPE", "超期事项");
                        break;
                    case "3":
                        mapMsg.put("MSGTYPE", "延期事项");
                        break;
                    case "4":
                        mapMsg.put("MSGTYPE", "审批提醒");
                        break;
                    case "5":
                        mapMsg.put("MSGTYPE", "维修提醒");
                        break;
                    case "6":
                        mapMsg.put("MSGTYPE", "维护提醒");
                }
                listMsg.add(mapMsg);
            }
            return listMsg;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new ApiRRException(e.getMessage());
        }
    }
}
